function* generator1() { 
  console.log(' Execution started');
  yield 0;
  console.log(' Execution resumed');
  yield 1;
  console.log(' Execution end');
}
const iterator1 = generator1();
console.log('iterator1', iterator1);

console.log(iterator1.next());
// "Execution started"
// { value: 0, done: false }
console. log( iterator1. next());
// "Execution resumed"
// { value: 1, done: false }
console. log( iterator1. next());
// "Execution end"
// { value: undefined, done: true }
console. log( iterator1. next());
// { value: undefined, done: true }

function* say() {
  const name = yield
  console.log('hello ' + name) // 2. hello typescript
}
const res = say()
console.log(res.next()); // 1. {value: undefined, done: false}
console.log(res.next('typescript')); // 3. {value: undefined, done: true}
 
function* generator2() {
  try {
    yield 1;
  }catch (error) {
    console.log(error.message);
  }
}
const iterator2 = generator2();
console.log(iterator2.next());// {value: 1, done: false}
const error = iterator2.throw( new Error(' something incorrect'));
console.log(error);// something incorrect // {value: undefined, done: true}
